# coding: utf-8

"""
    @Author :   zsj
    @File   :   response.py
    @Time   :   2024-08-06
"""

from fastapi.responses import JSONResponse
from fastapi import status
from fastapi.encoders import jsonable_encoder
from src.common import status as l_status
from src.core.logconfig import log


def success_response(d, m:str='None'):
	""" 请求成功处理 """
	
	data = {
		"code": l_status.HTTP_SUCCESS,
		"message": l_status.HTTP_SUCCESS_MSG if m is None else m,
		"data": d
	}
	# log.logger.info(f"success_response: {data}")
	data = jsonable_encoder(data)
	return JSONResponse(content=data, status_code=status.HTTP_200_OK)


def fail_response(d):
	"""
	失败响应
	"""
	data = {
		"code": l_status.HTTP_FAIL,
		"message": d,
		"data": []
	}
	return JSONResponse(content=data, status_code=l_status.HTTP_FAIL)
